package com.app.service.impl;

import cn.hutool.core.util.StrUtil;
import com.app.mapper.AdminUserMapper;
import com.app.mapper.FileClassMapper;
import com.app.model.AdminUserModel;
import com.app.model.AttachmentModel;
import com.app.model.FileClassModel;
import com.app.service.FileClassService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Primary
public class FileClassServiceImpl extends ServiceImpl<FileClassMapper, FileClassModel>  implements FileClassService {
   @Autowired
   FileClassMapper fileClassMapper;

    @Override
    public List<FileClassModel> getModelList(Integer pid,String keyword) {
        QueryWrapper<FileClassModel> queryWrapper = new QueryWrapper<>();
        if (StrUtil.isNotBlank(keyword)){
            queryWrapper.like("name",keyword);
        }
        if (pid != null && pid != 0) {
            queryWrapper.eq("status", 1);
        }
        queryWrapper.orderByDesc("sort").orderByAsc("id");
        List<FileClassModel> modelList = fileClassMapper.selectList(queryWrapper);
        return modelList;
    }

    @Override
    public FileClassModel getModel(int id) {
        QueryWrapper<FileClassModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select().eq("id", id);
        FileClassModel role =  fileClassMapper.selectOne(queryWrapper);
       return role;
    }

    @Override
    public List<FileClassModel> getModelListByPid(int pid) {
        QueryWrapper<FileClassModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pid", pid);
        List<FileClassModel> modelList = fileClassMapper.selectList(queryWrapper);
        return modelList;
    }
}
